'use strict';

angular.module('metalabPartnerApp').directive('metaFormCompareTo', function () {
    return {
        restrict: 'A',
        require: '?ngModel',
        scope: {
            bindData: '=metaFormCompareTo'
        },
        link: function (scope, elem, attrs, ngModel) {
            //elem.bind('click', function (event) {
            //    if (event.target.checked) {
            //        scope.bindData.push(elem.val());
            //    } else {
            //        scope.bindData.splice(scope.bindData.indexOf(elem.val()), 1);
            //    }
            //    scope.$apply();
            //});
            ngModel.$validators.metaFormCompareTo = function (modalValue) {
                if (scope.bindData !== undefined) {
                    return modalValue === scope.bindData;
                } else {
                    return false;
                }
            };

            scope.$watch('bindData', function () {
                ngModel.$validate();
            });
        }
    };
});
